package ictbk.ttmk51.grapro.app;

import ictbk.ttmk51.grapro.app.androidexplorer.AndroidExplorerActivity;
import ictbk.ttmk51.grapro.app.safeapplication.SafeApplication;
import ictbk.ttmk51.grapro.app.safedocument.SafeDocumentActivity;
import ictbk.ttmk51.grapro.app.safeimage.SafeImageActivity;
import ictbk.ttmk51.grapro.app.safephonebook.SafePhoneBookActivity;
import ictbk.ttmk51.grapro.app.safesms.SafeSMSActivity;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {
	
	private Button btnPhoneBook;
	private Button btnSMS;
	private Button btnImage;
	private Button btnDocument;
	private Button btnApplication;
	private Button btnBack;
	private Button btnExit;
	private Button btnAndroidExplorer;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_LEFT_ICON);
        setContentView(R.layout.main_screen);
        setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.backup_data);
        
        btnPhoneBook = (Button)findViewById(R.id.btnPhoneBook);
        btnDocument = (Button)findViewById(R.id.btnDocument);
        btnApplication = (Button)findViewById(R.id.btnApplication);
        btnImage = (Button)findViewById(R.id.btnImage);
        btnSMS = (Button)findViewById(R.id.btnSMS);
        btnBack = (Button)findViewById(R.id.btnBack);
        btnExit = (Button) findViewById(R.id.btnExit);
        btnAndroidExplorer = (Button) findViewById(R.id.btnAndroidExplorer);
        
        
        btnPhoneBook.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(MainActivity.this, SafePhoneBookActivity.class);
				startActivity(intent);
			}
		});
        
        btnSMS.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(MainActivity.this, SafeSMSActivity.class);
				startActivity(intent);
			}
		});
        
        btnImage.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(MainActivity.this, SafeImageActivity.class);
				startActivity(intent);
			}
		});
        
        btnDocument.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(MainActivity.this, SafeDocumentActivity.class);
				startActivity(intent);
			}
		});
        
        btnApplication.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(MainActivity.this, SafeApplication.class);
				startActivity(intent);
			}
		});
        
        btnAndroidExplorer.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(MainActivity.this, AndroidExplorerActivity.class);
				startActivity(intent);
			}
		});
        
        btnBack.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
        
        btnExit.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent exit_intent = new Intent(MainActivity.this, LoginActivity.class);
				exit_intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				exit_intent.putExtra("EXIT", true);
				startActivity(exit_intent);
			}
		});
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu){
    	MenuInflater inflater = getMenuInflater();
    	inflater.inflate(R.menu.main_menu, menu);
    	return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item){
    	switch(item.getItemId()){
    	case R.id.changePassword:
    		Toast.makeText(this, "You changed password!", Toast.LENGTH_SHORT).show();
    		customChangePasswordAlertDialog();
    		break;
    	}
    	return false;
    }
    
    //Change Pasword
    public void customChangePasswordAlertDialog(){
    	AlertDialog.Builder changePasswordScreen = new AlertDialog.Builder(this);
    	changePasswordScreen.setTitle("Create New Account");
    	changePasswordScreen.setIcon(R.drawable.change_password);
    	
    	LayoutInflater vi = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
    	View content = vi.inflate(R.layout.change_password_screen, null);
    	changePasswordScreen.setView(content);
    	changePasswordScreen.setPositiveButton("OK", new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				// TODO Auto-generated method stub
			}
		});
    	
    	changePasswordScreen.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				// TODO Auto-generated method stub
				
			}
		});
    	
    	changePasswordScreen.show();
    }
}